home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / saveNodePresetDialog.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.6 KB  |  237 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  September 1, 2000
  22. //  Author:         jdc rendering
  23. //
  24. // Description:
  25. //
  26. //        This file contains the procedures to build the node preset naming 
  27. //         window and various error checking windows.
  28. //                                                
  29.  
  30. global proc invalidNodePresetNameDialog(string $name)
  31. //
  32. // Description:
  33. //    This procedure is called when the user has typed an invalid preset name
  34. //    into the text field of the save preset dialog and hit enter, or 
  35. //     hit the OK button in the save preset dialog box while and invalid name
  36. //     is displayed in the text field.
  37. //    This procedure displays a dialog telling the user they have typed an
  38. //    invalid preset name, and describing what constitutes an invalid preset
  39. //    name.
  40. //
  41. {
  42.     string $message = "The name \""
  43.                     + $name
  44.                     + "\" is an invalid preset name.\n"
  45.                     + "Valid preset names can contain only letters, numbers "
  46.                     + "and underscores.";
  47.  
  48.     $confirmResponse = `confirmDialog 
  49.         -title "Invalid Preset Name"
  50.         -parent saveNodePresetDialogWindow
  51.         -button "OK" -defaultButton "OK"
  52.         -message $message
  53.         -messageAlign "left"`;
  54. }
  55.  
  56. global proc int confirmOverwriteDialog(
  57.     string $presetName)
  58. //
  59. // Description:
  60. //    This procedure is called when the user has asked to save the settings
  61. //    of a node under a certain preset name, but a preset already exists by
  62. //    that name for that node.
  63. //    This procedure displays a dialog prompting the user to confirm that
  64. //    they want to overwrite the existing preset.
  65. //    If the user chooses "OK", the preset is overwritten. If the user
  66. //    chooses "Cancel", this dialog closes and the preset is not written.
  67. //
  68. {
  69.     string $message = "A preset by the name \""
  70.                     + $presetName
  71.                     + "\" already exists.\n"
  72.                     + "Overwrite it?";
  73.  
  74.     $confirmResponse = `confirmDialog 
  75.         -title "Overwrite Existing Preset?"
  76.         -parent saveNodePresetDialogWindow
  77.         -button "Overwrite" -button "Cancel"
  78.         -cancelButton "Cancel" -defaultButton "Cancel"
  79.         -message $message
  80.         -messageAlign "left"`;
  81.  
  82.     int $isOverwritten = false;
  83.  
  84.     if ("Overwrite" == $confirmResponse) {
  85.         $isOverwritten = true;
  86.     }
  87.     return $isOverwritten;
  88. }
  89.  
  90. global proc saveNodePresetDialogValidateName(
  91.     string $presetNameGrp,
  92.     int $performOperationIfValid)
  93. {
  94.     //
  95.     // Description:
  96.     //    This procedure is called when the user has typed a name for the preset
  97.     //    they are trying to save and we need to verify that the name they have
  98.     //    typed is actually valid.
  99.     //    This method uses the nodePreset command to determine if the name typed
  100.     //    by the user is valid. If the name is valid, and
  101.     //    $performOperationIfValid is true, this procedure will proceed to
  102.     //    perform the saving of the preset using the name typed by the user.
  103.     //  If the name is invalid, a dialog will be displayed to illustrate to the
  104.     //  user the error of their ways.
  105.     //    $presetNameGrp is the name of the textFieldGrp control which contains
  106.     //    what the user has typed.
  107.     //
  108.  
  109.     string $globalsNodes[] = `renderer -q -globalsNodes (currentRenderer())`;
  110.     string $presetName;
  111.  
  112.     $presetName = `textFieldGrp -query -text $presetNameGrp`;
  113.  
  114.     if (!`nodePreset -isValidName $presetName`)
  115.     {
  116.         invalidNodePresetNameDialog($presetName);
  117.     }
  118.     else if ($performOperationIfValid)
  119.     {
  120.         string $savePreset = true;
  121.         if (`nodePreset -exists $globalsNodes[0] $presetName`)
  122.         {
  123.             // If a preset already exists by that name, we will confirm
  124.             // before overwriting it.
  125.             //
  126.             $savePreset =  confirmOverwriteDialog($presetName);
  127.         }
  128.         if ($savePreset)
  129.         {
  130.             int $i;
  131.             for ($i = 0; $i < size($globalsNodes); $i++)
  132.             {
  133.                 nodePreset -save $globalsNodes[$i] $presetName;
  134.             }
  135.         }
  136.         deleteUI saveNodePresetDialogWindow;
  137.     }
  138. }
  139.  
  140. global proc saveNodePresetDialog()
  141. {
  142.     //
  143.     // Description:
  144.     //    This method is called when a user wants to save the settings of a node
  145.     //    to a preset.
  146.     //    This procedure displays the main dialog for preset saving, which allows
  147.     //    the user to type in the name by which they would like the preset to be
  148.     //    known.
  149.     //
  150.     if (`window -exists saveNodePresetDialogWindow`)
  151.     {
  152.         deleteUI saveNodePresetDialogWindow;
  153.     }
  154.  
  155.     if (`windowPref -exists saveNodePresetDialogWindow`)
  156.     {
  157.         windowPref 
  158.             -remove
  159.             saveNodePresetDialogWindow;
  160.     }
  161.     
  162.     window 
  163.         -title "Save Settings as Preset"
  164.         -iconName "Save Preset"
  165.         saveNodePresetDialogWindow;
  166.  
  167.     formLayout mainLayout;
  168.         string $presetNameGrp;
  169.  
  170.         $presetNameGrp = 
  171.             `textFieldGrp
  172.                 -label "Preset Name:"
  173.                 -editable true`;
  174.         
  175.         text
  176.             -align center
  177.             -label 
  178.                 ("(Names can contain letters, numbers "
  179.                     + "and underscores.)")
  180.             helpText;
  181.         
  182.         formLayout 
  183.             -numberOfDivisions 2
  184.             buttonLayout;
  185.  
  186.             button
  187.                 -label "Save Preset"
  188.                 -command 
  189.                     ("saveNodePresetDialogValidateName \""
  190.                         + $presetNameGrp
  191.                         + "\" true")
  192.                 saveButton;
  193.             button
  194.                 -label "Cancel"
  195.                 -command "deleteUI saveNodePresetDialogWindow"
  196.                 cancelButton;
  197.             
  198.             formLayout 
  199.                 -edit
  200.  
  201.                 -af saveButton    "top"        0
  202.                 -af saveButton    "bottom"    0
  203.                 -af saveButton    "left"        0
  204.                 -ap saveButton    "right"        3 1
  205.  
  206.                 -af cancelButton    "top"        0
  207.                 -af cancelButton    "bottom"    0
  208.                 -ap cancelButton    "left"        3 1
  209.                 -af cancelButton    "right"        0
  210.                 
  211.                 buttonLayout;
  212.  
  213.         setParent ..;
  214.  
  215.         formLayout
  216.             -edit
  217.  
  218.             -af $presetNameGrp    "top"        5
  219.             -af $presetNameGrp    "left"        5
  220.             -af $presetNameGrp    "right"        5
  221.  
  222.             -ac helpText    "top"        5 $presetNameGrp
  223.             -af helpText    "left"        5
  224.             -af helpText    "right"        5
  225.             -ac helpText    "bottom"    5 buttonLayout
  226.  
  227.             -an buttonLayout    "top"
  228.             -af buttonLayout    "bottom"    5
  229.             -af buttonLayout    "left"        5
  230.             -af buttonLayout    "right"        5
  231.  
  232.             mainLayout;
  233.     setParent ..;
  234.  
  235.     showWindow saveNodePresetDialogWindow;
  236. }
  237.